package org.snusmumr.android.media.data;

import org.snusmumr.android.media.data.DatabaseProvider.DatabaseMode;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class DeleteMediaItemOperation extends DBOperation<Boolean> {
	private long itemId;

	public DeleteMediaItemOperation(Context context, long itemId) {
		super(context);
		this.itemId = itemId;
	}
	
	@Override
	protected DatabaseMode getDatabaseMode() {
		return DatabaseMode.Write;
	}

	@Override
	public Boolean execute() {
		SQLiteDatabase database = getDatabaseProvider().getDatabase(getDatabaseMode());
		database.beginTransaction();
		boolean res = false;
		try {
			res = deleteItem();
			if(res) {
				res = deleteAuthor();
			}
			if(res)
				database.setTransactionSuccessful();
		} finally {
			database.endTransaction();
		}
		
		// clean up friends
		new FriendCollectorOperation(getContext()).execute();
		
		return res;
	}
	
	private boolean deleteItem() {
		return false;
	}
	
	/**
	 * check if no other items by this author, delete the author too.
	 * @return
	 */
	private boolean deleteAuthor() {
		return false;
	}

}
